package com.xdcplus.web.common.pojo.dto.sms;

import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Collections;
import java.util.List;

/**
 * @author Zhecheng.Ren
 * @since 2024/10/23 14:41
 */
@Data
public class SmsDTO {
    private String contentType;

    private ReceiveDTO receive;

    private String message;

    private String messageTemplateCode;

    private Object parameters;

    private String title;

    @Data
    public static class Builder {
        SmsDTO smsDTO = new SmsDTO();

        public SmsDTO.Builder addMessage(String message) {
            smsDTO.setMessage(message + DateUtil.formatDateTime(DateUtil.date()));
            return this;
        }

        public SmsDTO.Builder addTitle(String title) {
            smsDTO.setTitle(title);
            return this;
        }

        public SmsDTO.Builder addMessageTemplateCode(String messageTemplateCode) {
            smsDTO.setMessageTemplateCode(messageTemplateCode);
            return this;
        }

        public SmsDTO.Builder addParameters(Object parameters) {
            smsDTO.setParameters(parameters);
            return this;
        }

        public SmsDTO.Builder addGroupCodes(List<String> groupCodes) {
            ReceiveDTO receive = smsDTO.getReceive();
            if (receive == null) {
                receive = new ReceiveDTO();
            }
            receive.setGroupCodes(groupCodes);
            smsDTO.setReceive(receive);
            return this;
        }

        public SmsDTO.Builder addUserIds(List<Long> userIds) {
            ReceiveDTO receive = smsDTO.getReceive();
            if (receive == null) {
                receive = new ReceiveDTO();
            }
            receive.setUserIds(userIds);
            smsDTO.setReceive(receive);
            return this;
        }

        public SmsDTO.Builder addAccounts(List<String> accounts) {
            ReceiveDTO receive = smsDTO.getReceive();
            if (receive == null) {
                receive = new ReceiveDTO();
            }
            receive.setAccounts(accounts);
            smsDTO.setReceive(receive);
            return this;
        }

        public SmsDTO.Builder addPositionIds(List<Long> positionIds) {
            ReceiveDTO receive = smsDTO.getReceive();
            if (receive == null) {
                receive = new ReceiveDTO();
            }
            receive.setPositionIds(positionIds);
            smsDTO.setReceive(receive);
            return this;
        }

        public SmsDTO.Builder addContentType(String contentType) {
            smsDTO.setContentType(contentType);
            return this;
        }

        public SmsDTO build() {
            return smsDTO;
        }
    }

}

@Data
class ReceiveDTO {

    private List<String> groupCodes = Collections.emptyList();

    /**
     * 用户ID集合
     */
    @ApiModelProperty("用户ID集合")
    private List<Long> userIds = Collections.emptyList();

    /**
     * 所属岗位ID
     */
    @ApiModelProperty(value = "所属岗位ID")
    private List<Long> positionIds = Collections.emptyList();

    private List<String> accounts = Collections.emptyList();
}
